/** 
 */

var url='index.jsp?inc=./FmBoard/';
extArray = new Array(".gif", ".jpg", ".png"); //첨부가능한 확장자 목록

function general(){ 
	if(document.getElementById('btnList') != null){
		document.getElementById('btnList').onclick=function(){
			var frm=document.hiddenFrm;
			frm.action=url+'bList.jsp';
			frm.submit();
		}	
	}
	if(document.getElementById('btnInput') != null){
		document.getElementById('btnInput').onclick=function(){
			var frm=document.hiddenFrm;
			var m=frm.smid.value;
			if(m==""){
				location.href='index.jsp?inc=./member/loginMember.jsp';
			}else{
				frm.action=url+'bInput.jsp';
				frm.submit();
			}
		}
	}
	if(document.getElementById('btnDelete') != null){
		document.getElementById('btnDelete').onclick=function(){
			var b = confirm("정말 삭제하시겠습니까??");
			if(b){
				var frm=document.hiddenFrm;
				frm.action=url+'bDelete_result.jsp';
				frm.submit();
			}else{
				alert("삭제작업이 취소되었습니다.");
			}
		}
		
	}
	if(document.getElementById('btnView') != null){
		document.getElementById('btnView').onclick=function(){
			var frm=document.hiddenFrm;
			frm.action=url+'bView.jsp';
			frm.submit();
		}
	}
	if(document.getElementById('btnModify') != null){
		document.getElementById('btnModify').onclick=function(){
			var frm=document.hiddenFrm;
			frm.action=url+'bModify.jsp';
			frm.submit();
		}
	}
}

function goPage(page){
	var mf = document.hiddenFrm;
	mf.nowPage.value = page;
	mf.find.value= document.board_list_frm.find.value;
	mf.action='index.jsp?inc=./FmBoard/bList.jsp';
	
	mf.submit();
}

function modiPage(mrno){
	location.href=url+'bModify.jsp?rno='+mrno;
}

function goView(page, rno){
	var mf = document.hiddenFrm;
	mf.nowPage.value = page;
	if(document.board_list_frm != null){
	mf.find.value= document.board_list_frm.find.value;}
	mf.rno.value=rno;
	mf.action='index.jsp?inc=./FmBoard/bView.jsp';
	
	mf.submit();
}

function newPic(pic){
	  window.open(pic,"newnewnew","");
}




function bInputInit(){ // input과 관련된 모듈
	general(); 
	if(document.getElementById('btnSave')!= null){
		document.getElementById('btnSave').onclick=function(){
			var f = document.hiddenFrm;
			var file = f.pic.value
			allowSubmit = false;
		    if (!file) return;
		    ext = file.slice(file.indexOf(".")).toLowerCase();
		    for (var i = 0; i < extArray.length; i++) {
		        if (extArray[i] == ext) { allowSubmit = true; break; }
		    }
		    
		    if (allowSubmit==false) {
		  
		        alert("업로드 가능한 확장자는 " + (extArray.join("  ")) + "입니다.");
		        return;
		    }else{
		
			if(f.subject.value==''){
				alert("제목,내용을 입력해주세요.");
				f.subject.focus();
			}else if(f.content.value==''){
				alert("제목,내용을 입력해주세요.");
				f.content.focus();
			}else{
				f.action='index.jsp?inc=./FmBoard/bInput_result.jsp';
				f.submit();
			}
		    }
			
	}

}
}
function bListInit(){
	general();
}
function bViewInit(){
	general();
	if(document.getElementById('btnRep')!=null){
		document.getElementById('btnRep').onclick=function(){
			var ff = document.hiddenFrm;
			if(ff.mid.value==""){
				location.href='index.jsp?inc=./member/loginMember.jsp';
			}else{
				ff.action='index.jsp?inc=./FmBoard/bRepInput.jsp';
				ff.submit();
			}
		}
	}
}
function bModifyInit(){
	general();
	if(document.getElementById('btnSave')!=null){
		document.getElementById('btnSave').onclick=function(){
			var f = document.hiddenFrm;
			var file = f.pic.value
			allowSubmit = false;
		    if (!file) return;
		    ext = file.slice(file.indexOf(".")).toLowerCase();
		    for (var i = 0; i < extArray.length; i++) {
		        if (extArray[i] == ext) { allowSubmit = true; break; }
		    }
		    
		    if (allowSubmit==false) {
		  
		        alert("업로드 가능한 확장자는 " + (extArray.join("  ")) + "입니다.");
		        return;
		    }else{
		
				f.action='index.jsp?inc=./FmBoard/bModify_result.jsp';
				f.submit();
		    }
		}	
	}
}
function bDeleteInit(){
	general();
}

function bRepInit(){
	general();
	if(document.getElementById('btnSave')!=null){
		document.getElementById('btnSave').onclick=function(){
			var f = document.hiddenFrm;
			f.action='index.jsp?inc=./FmBoard/bRepInput_result.jsp';
			f.submit();
		
		}
	}
}
